import pandas as pd

import numpy as np


dates = pd.Series(pd.date_range('20240628', periods=5))
df = pd.DataFrame(np.random.randn(5, 4), index=dates, columns=list("ABCD"))
print(df)
# DataFrame.T 转置数据
# print(df.T)
#  DataFrame.sort_index 索引 axis 0 index 1 列
# print(df.sort_index(axis=0, ascending=False))
# by 根据某列排序
# print(df.sort_values(by='B'))
# 切片行左闭右开
# print(df[0:3])
"""
根据标签索引
1 标签索引
"""
# DataFrame 索引 索引支持 np service 和 python 字符串和列表
# print(dates[0:2])
# loc DataFrame 索引
# print(df.loc[dates[0:2]])
# loc DataFrame 索引 and 列索引
# print(df.loc[dates[0:2], ['A', 'B']])
# print(df.loc[dates[0], 'A'])
"""
根据位置选择
"""
# print(df.iloc)

"""
分组聚合
tmp = df.groupby(df['ts'].dt.date)['A']
tmp.max()
tmp.min()
差值
_df = df.groupby(df['ts'].dt.hour)['A'].agg(lambda x: x.max() - x.min())
"""